﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>无标题页</title>
    <script type="text/javascript">
    <!--千万注意i的变量域-->
    <!--By Aaron-->
function fun()
{
    var args=arguments;
    this.func=arguments[0];    
    this.arg=function(){
       if(args.length>1)
       {
          var list=[];
          for(var i=1;i<args.length;i++)
          {
             list.push(args[i]);
          }
          return list;
       }else{
          return null;
       }       
    }
    this.execute=function(){
        var o=window;
        this.func.call(o,this.arg());        
    }    
}

function delegate()
{
   this.list=[];
   this.add=function(fun)
   {
      this.list.push(fun);
   }
   this.remove=function(obj)
   {
     for(var i=0;i<this.list.length;i++)
     {
         if(this.list[i].fun==obj)
         {
            this.list.pop(this.list[i]);
            return true;
         }
     }
     return false;
   }
   this.execute=function()
   {
      for(var i=0;i<this.list.length;i++)
      {
          var objfun=this.list[i];         
          objfun.execute();
      }
   }
}


    </script>
</head>
<body>
<div id="inner" style="border:1px #b5b5b5 solid; width:600px; height:400px">cctv

</div>
</body>
</html>
<script type="text/javascript">
function test(str)
{
   //document.getElementById('inner').innerHTML+=str;
   alert(str);
}
function test1(stb,stc)
{
   alert(stb+'=='+stc);
}
var dels=new delegate();
/*
var funb=new fun(confirm,'Aaronb');
var funa=new fun(alert,'Aarona1');
var func=new fun(alert,'Aaronc');*/

var funb=new fun(test,'Aaronb<br>');
var funa=new fun(test1,'Aarona1<br>','jjww');
var func=new fun(test,'Aaronc<br>');
dels.add(funb);
dels.add(funa);
dels.add(func);

dels.execute();
</script>
